package communication.message;

import exception.BadArgumentValueException;

/***
 * 
 * @author Bogusław Zaręba
 *
 */

public class Player {
	public static int UNSET = -1;
	
	private String nick; 
	private Result result;
	private int won = UNSET, lost = UNSET;
	
	public Player(String nick) {
		this.nick = nick;
	}
	
	public Player(String nick, Result result) {
		this.nick = nick;
		this.result = result;
	}
	
	public Player(String nick, int won, int lost) throws BadArgumentValueException {
		this.nick = nick;
		if(won < 0 || lost < 0)
			throw new BadArgumentValueException("Player(nick, won, lost) - won and lost must be possitive");
		this.won = won;
		this.lost = lost;
	}
	
	public String getNick() {
		return nick;
	}
	
	public Result getResult() {
		return result;
	}
	
	public int getWon() {
		return won;
	}
	
	public int getLost() {
		return lost;
	}
	
	public String toString() {
		if(result != null)
			return XMLTagCreator.singleTag("player", "nick", nick, "result", "" + result);
		if(won != -1) 
			return XMLTagCreator.singleTag("player", "nick", nick, "won", "" + won, "lost", "" + lost);
		return XMLTagCreator.singleTag("player", "nick", nick);
	}
}
